package com.leyou.item.service;

import com.leyou.pojo.Item;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 76053
 * @version v1.0
 * @date 2019/6/22 19:40
 **/
@RestController
@RequestMapping("item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @PostMapping
    public ResponseEntity<Item> test(Item item) {
//        if(item.getPrice() == null){
//            //return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
//            throw new RuntimeException("价格不能为空");
//        }
//        Item result = itemService.saveItem(item);
//        return ResponseEntity.status(HttpStatus.CREATED).body(result);
        if(item.getPrice() == null){
            //throw new LyException(ExceptionEnum.);
        }
        Item result = itemService.saveItem(item);
        return ResponseEntity.ok(result);
    }

}
